<?php
declare(strict_types=1);
/**
 * Created by project.
 * User: huanzipap
 * Date: 2023/5/10
 * Time: 11:25
 */

namespace App\Controller\User;

use App\Controller\AppBaseController;
use App\Model\Act;
use App\Model\ActAnswer;
use App\Model\ActAnswerRule;
use App\Model\ActAnswerJoin;
use App\Model\ActAnswerLog;
use App\Model\ActAnswerQuestion;
use App\Model\ActAnswerAnswer;
use App\Model\ActJoin;
use Hyperf\DbConnection\Db;


use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\WxApiAuth;

#[Controller(prefix: 'user')]
#[Middleware(WxApiAuth::class)]

class AnswerController extends AppBaseController
{
    /**
     * 获取本次活动题库
     * @param int $act_id
     * @return object
     */
    #[RequestMapping(path:'questionList/{act_id}',methods: 'get')]
    public function questionList(int $act_id): object
    {
        try{
            //验证用户信息
            $checkInfo = $this->checkUser();
            if($checkInfo['status']==40002) return $this->reMsg->re(10002,$checkInfo['message']);
            $_user = $checkInfo['data'];

            //先获取本次答题活动
            $info = Act::with(['answerRule'])->where('id',$act_id)->first();
            if(empty($info)) return $this->reMsg->re(10008);

            if($info->type != 1) return $this->reMsg->re(0,'活动类型有误');

            //判断开始时间
            if($info->start_time && time()<strtotime($info->start_time)) return $this->reMsg->re(0,'活动未开始');
            //判断结束时间
            if($info->end_time && time()>strtotime($info->end_time)) return $this->reMsg->re(0,'活动已结束');
            //判断数量超出
            if($info->join_count>=$info->max_limit) return $this->reMsg->re(0,'参与人数超过限制');

            //整理答题规则
            if($info->answerRule){
                $answerRuleInfo = $info->answerRule;
            }else{
                $answerRuleInfo = ActAnswerRule::where('act_id',$info->id)->first();
            }

            if(empty($answerRuleInfo) || !in_array($answerRuleInfo->extract_type,[1,2,3])) return $this->reMsg->re(0,'题库规则有误');

            $extractType = $answerRuleInfo->extract_type; //复制抽题类型

            $answerJoinLog = ActAnswerJoin::getActAnswerJoin($act_id,$_user->id);

            if($answerJoinLog && $answerJoinLog->answer_total_num>0){
                    $backRet = [
                        'answer_true'=>$answerJoinLog->answer_true,
                        'answer_score'=>$answerJoinLog->answer_score,
                        'answer_score_up'=>$answerJoinLog->answer_score_up
                    ];
                    //答题总次数大于3，表示已经答过题了
                    if($answerJoinLog->answer_total_num>=$answerRuleInfo->limit_time){
                        return $this->reMsg->re(10010,'答题次数已达上限',$backRet);
                    }
                    //判断今天是否答题
//                    $todayDate = date('Y-m-d',time());
//                    $todayStartStr = strtotime($todayDate);
//                    $todayEndStr = $todayStartStr + 3600 * 24 - 1;
//                    if($answerJoinLog->answer_time>$todayStartStr && $answerJoinLog->answer_time<$todayEndStr){
//                        return $this->reMsg->re(0,'今天答过题了',$backRet);
//                    }
            }

            //获取用户已经答题的question_ids
//            $readyAnswerList = ActAnswerLog::selectRaw('id,uid,question_id')
//                ->where('uid',$_user->id)
//                ->orderByDesc('id')
//                ->get();
//            $readyQuestionArr = [];
//            $i=1;
//            foreach ($readyAnswerList as $key=>$value){
//                $readyQuestionArr[$i++] = $value->question_id;
//            }
            //获取题目列表
            $questionList = ActAnswerQuestion::selectRaw('id,type')
                ->where(['act_id'=>$act_id,'status'=>1])
                //->whereNotIn('id',$readyQuestionArr)
                ->get();

            $list = [];

            if($questionList->isNotEmpty()){
                //整理题库
                //题库id
                $questionIds = [];
                if($extractType==3){
                    //指定单选、多选、判断题目数量
                    $danxuanArr = [];
                    $i=0;
                    $duoxuanArr = [];
                    $j=0;
                    $panduanArr = [];
                    $n=0;
                    foreach ($questionList as $key=>$value){
                        if($value->type==1){
                            $danxuanArr[$i] = $value->id;
                            $i++;
                        }else if($value->type==2){
                            $duoxuanArr[$j] = $value->id;
                            $j++;
                        }else if($value->type==3){
                            $panduanArr[$n] = $value->id;
                            $n++;
                        }
                    }
                    //指定单选、多选、判断各自多少题
//                    $danxuanNeedNum = 2;
//                    $duoxuanNeedNum = 2;
//                    $panduanNeedNum = 2;
                    $danxuanNeedNum = $answerRuleInfo->dan_num;
                    $duoxuanNeedNum = $answerRuleInfo->duo_num;
                    $panduanNeedNum = $answerRuleInfo->pan_num;

                    //整理最终题库
                    $m=0;
                    //整理单选题
                    if($danxuanArr && $danxuanNeedNum>0){
                        if(count($danxuanArr)>$danxuanNeedNum){
                            if($danxuanNeedNum==1){
                                $danxuan_tiku_ids[0] = array_rand($danxuanArr,$danxuanNeedNum);
                            }else{
                                $danxuan_tiku_ids = array_rand($danxuanArr,$danxuanNeedNum);
                            }
                        }else{
                            $danxuan_tiku_ids = $danxuanArr;
                        }
                        foreach($danxuan_tiku_ids as $danKey=>$danVal){
                            $questionIds[$m] = $danVal;
                            $m++;
                        }
                    }

                    //整理多选题
                    if($duoxuanArr && $duoxuanNeedNum>0){
                        if(count($duoxuanArr)>$duoxuanNeedNum){
                            if($duoxuanNeedNum==1){
                                $duoxuan_tiku_ids[0] = array_rand($duoxuanArr,$duoxuanNeedNum);
                            }else{
                                $duoxuan_tiku_ids = array_rand($duoxuanArr,$duoxuanNeedNum);
                            }
                        }else{
                            $duoxuan_tiku_ids = $duoxuanArr;
                        }
                        foreach($duoxuan_tiku_ids as $duoKey=>$duoVal){
                            $questionIds[$m] = $duoVal;
                            $m++;
                        }
                    }

                    //整理判断题
                    if($panduanArr && $panduanNeedNum>0){
                        if(count($panduanArr)>$panduanNeedNum){
                            if($panduanNeedNum==1){
                                $panduan_tiku_ids[0] = array_rand($panduanArr,$panduanNeedNum);
                            }else{
                                $panduan_tiku_ids = array_rand($panduanArr,$panduanNeedNum);
                            }
                        }else{
                            $panduan_tiku_ids = $panduanArr;
                        }
                        foreach($panduan_tiku_ids as $panKey=>$panVal){
                            $questionIds[$m] = $panVal;
                            $m++;
                        }
                    }
                }else{
                    //顺序抽取（全部题目）
                    $a=0;
                    foreach($questionList as $key=>$value){
                        $questionIds[$a++] = $value->id;
                    }
                    //限制抽取数量
                    if($extractType==2){
                        $extractNum = $answerRuleInfo->extract_num;
                        //随机抽取（全部题目）
                        if($extractNum<=0){
                            return $this->reMsg->re(0,'请设置抽取题目总数大于0');
                        }
                        if(count($questionIds)>$extractNum){
                            if($extractNum==1){
                                $randomIds[0] = array_rand($questionIds,$extractNum);
                            }else{
                                $randomIds = array_rand($questionIds,$extractNum);
                            }
                            $randomArr = [];
                            $r = 0;
                            foreach($randomIds as $rKey=>$rVal){
                                $randomArr[$r++] = $questionIds[$rVal];
                            }
                            $questionIds = $randomArr;
                        }
                    }
                }
                $list = ActAnswerQuestion::with(['answers'=>function($query){
                    $query->selectRaw('id,question_id,answer_title,answer_xuan')->get();
                }])->whereIn('id',$questionIds)->get();
            }
            return $this->reMsg->re(1,'success',['list'=>$list]);
        }catch (\Exception $exception){
            return $this->diyError->errorJson($exception);
        }
    }


    /**
     * 提交答题信息
     * @param int $act_id
     * @return object
     */
    #[RequestMapping(path: 'subAnswerData/{act_id}',methods: 'post,get')]
    public function subAnswerData(int $act_id) :object
    {
        try{
            //验证用户信息
            $checkInfo = $this->checkUser();
            if($checkInfo['status']==40002) return $this->reMsg->re(10002,$checkInfo['message']);
            $_user = $checkInfo['data'];

            //先获取本次答题活动
            $info = Act::with(['answerRule'])->where('id',$act_id)->first();
            if(empty($info)) return $this->reMsg->re(10008);
            if($info->type != 1) return $this->reMsg->re(0,'活动类型有误');

            //判断开始时间
            if($info->start_time && time()<strtotime($info->start_time)) return $this->reMsg->re(0,'活动未开始');
            //判断结束时间
            if($info->end_time && time()>strtotime($info->end_time)) return $this->reMsg->re(0,'活动已结束');
            //判断参与人数
            if($info->max_limit>0 && $info->join_count>=$info->max_limit) return $this->reMsg->re(0,'参与人数超过限制');

            //整理答题规则
            if($info->answerRule){
                $answerRuleInfo = $info->answerRule;
            }else{
                $answerRuleInfo = ActAnswerRule::where('act_id',$info->id)->first();
            }
            if(empty($answerRuleInfo) || !in_array($answerRuleInfo->extract_type,[1,2,3])) return $this->reMsg->re(0,'题库规则有误');


            $uid = $_user->id;
            $answerJoinLog = ActAnswerJoin::getActAnswerJoin($act_id,$uid);

            if($answerJoinLog && $answerJoinLog->answer_total_num>0) {
                $backRet = [
                    'answer_true' => $answerJoinLog->answer_true,
                    'answer_score' => $answerJoinLog->answer_score,
                    'answer_score_up' => $answerJoinLog->answer_score_up
                ];
                //答题总次数大于3，表示已经答过题了
                if ($answerJoinLog->answer_total_num>=$answerRuleInfo->limit_time) {
                    return $this->reMsg->re(10010, '答题次数已达上限', $backRet);
                }
                //判断今天是否答题
//                    $todayDate = date('Y-m-d',time());
//                    $todayStartStr = strtotime($todayDate);
//                    $todayEndStr = $todayStartStr + 3600 * 24 - 1;
//                    if($answerJoinLog->answer_time>$todayStartStr && $answerJoinLog->answer_time<$todayEndStr){
//                        return $this->reMsg->re(0,'今天答过题了',$backRet);
//                    }
            }else{
                $insertData['party_id'] = $_user->party_id;
                $insertData['uid'] = $uid;
                $insertData['act_id'] = $info->id;
                $answerJoinLog = ActAnswerJoin::create($insertData);
                //往活动主参与记录里面加入记录
                $insertData['act_type'] = $info->type;
                $insertData['title'] = $info->title;
                $insertData['photo'] = $info->photo;
                ActJoin::create($insertData);
            }


            //获取数据
            $postData = $this->request->post('data', null);
            $answer_used_second = $this->request->post('used_second', 0); //获取全部用时

            //虚拟数据
//            $answer_used_second = 1;
//            $postData = [
//                ['question_id'=>1, 'answer_xuan'=>[3]],
//                ['question_id'=>2, 'answer_xuan'=>[1,2]],
//                ['question_id'=>3, 'answer_xuan'=>[1]],
//            ];
            //虚拟数据

            if(empty($postData) || !is_array($postData)){
                return $this->reMsg->re(0,'答案数据丢失');
            }

            //整理获取的=>答题数据 post_data
            $answerData = [];
            foreach($postData as $pVal) {
                if(isset($pVal['question_id']) && $pVal['question_id']){
                    $answerData[$pVal['question_id']] = $pVal['question_id'];
                    //跟进答案
                    if(isset($pVal['answer_xuan']) && is_array($pVal['answer_xuan'])){
                        foreach ($pVal['answer_xuan'] as $aKey=>$aVal){
                            if($aKey==0){
                                $answerData[$pVal['question_id']] = (string)$aVal;
                            }else{
                                $answerData[$pVal['question_id']] .= '||' . (string)$aVal;
                            }
                        }
                    }
                }
            }
//            return $this->reMsg->re(0,'数据测试',$answerData);

            //存放所有答题题目的id
            $questionIds = [];
            $i=0;
            foreach ($answerData as $key=>$value){
                $questionIds[$i++] = $key;
            }

            $questionData = ActAnswerQuestion::with(['answers'=>function($query){
                    $query->orderBy('id')->get();
                }])
                ->selectRaw('id,type,question_title,true_answer_xuan,score')
                ->whereIn('id',$questionIds)
                ->get();
            if($questionData->isEmpty()){
                return $this->reMsg->re(0,'提交信息错误，未知题目');
            }

            //赋值用户信息
//            $userInfo = $this->user;

            //判断对应题目是否答题正确
            $answer_log = [];
            $total_score = 0;
            $dui_dan = 0;
            $dui_duo = 0;
            $dui_pan = 0;

//            return $this->reMsg->re(1,'test',$questionData);

            foreach ($answerData as $dKey=>$dVal){
                foreach ($questionData as $qKey=>$qVal){
                    //编写答题进程answer_log
                    $answer_log[$qKey]['party_id'] = $answerJoinLog->party_id;
                    $answer_log[$qKey]['act_id'] = $answerJoinLog->act_id;
                    $answer_log[$qKey]['count'] = $answerJoinLog->answer_total_num + 1;
                    $answer_log[$qKey]['answer_join_id'] = $answerJoinLog->id;
                    $answer_log[$qKey]['uid'] = $answerJoinLog->uid;
                    $answer_log[$qKey]['question_id'] = $qVal->id;
                    $answer_log[$qKey]['question_title'] = $qVal->question_title;
                    $answer_log[$qKey]['used_second'] = $answer_used_second;
                    $answer_log[$qKey]['created_at'] = date('Y-m-d H:i:s',time());
                    //循环对应题目
                    if($dKey == $qVal->id){
                        if($dVal){
                            //默认数据
                            $answer_log[$qKey]['true_xuan'] = null;
                            $answer_log[$qKey]['true_xuan_desc'] = null;
                            $answer_log[$qKey]['user_xuan'] = null;
                            $answer_log[$qKey]['user_xuan_desc'] = null;
                            //表示本地作答
                            if($qVal->type==2){
                                //多选题答题经过
                                foreach ($qVal->answers as $txKey=>$txVal){
                                    // 整理出正确答案
                                    $true_xuan_arr = explode('||',$qVal->true_answer_xuan);
                                    if(in_array($txVal->answer_xuan,$true_xuan_arr)){
                                        if($answer_log[$qKey]['true_xuan']==null){
                                            $answer_log[$qKey]['true_xuan'] = $txVal->answer_xuan;
                                            $answer_log[$qKey]['true_xuan_desc'] = $txVal->answer_xuan.':'.$txVal->answer_title;
                                        }else{
                                            $answer_log[$qKey]['true_xuan'] .= '||'.$txVal->answer_xuan;
                                            $answer_log[$qKey]['true_xuan_desc'] .= '||'.$txVal->answer_xuan.':'.$txVal->answer_title;
                                        }
                                    }
                                    //整理用户的选项
                                    foreach ($answerData as $uxKey=>$uxVal){
                                        //判断 改答案是否为本题答案
                                        if($qVal->id==$uxKey){
                                            //判断 改答案是否为本题答案
                                            $user_xuan_arr = explode('||',$uxVal);
                                            if(in_array($txVal->answer_xuan,$user_xuan_arr)){
                                                if($answer_log[$qKey]['user_xuan']==null){
                                                    $answer_log[$qKey]['user_xuan'] = $txVal->answer_xuan;
                                                    $answer_log[$qKey]['user_xuan_desc'] = $txVal->answer_xuan.':'.$txVal->answer_title;
                                                }else{
                                                    $answer_log[$qKey]['user_xuan'] .= '||'.$txVal->answer_xuan;
                                                    $answer_log[$qKey]['user_xuan_desc'] .= '||'.$txVal->answer_xuan.':'.$txVal->answer_title;
                                                }
                                            }
                                        }
                                    }
                                }
                            }else{
                                //这里是【单选 或 者判断】题答题经过
                                foreach ($qVal->answers as $aKey=>$aVal){
                                    if($qVal->true_answer_xuan == $aVal->answer_xuan){
                                        //                                   //这是系统的正确答案
                                        $answer_log[$qKey]['true_xuan'] = $aVal->answer_xuan;
                                        $answer_log[$qKey]['true_xuan_desc'] = $aVal->answer_xuan.':'.$aVal->answer_title;
                                        break;
                                    }
                                }
                                foreach ($qVal->answers as $aKey=>$aVal){
                                    //判断用户是否答对
                                    if($dVal==$aVal->answer_xuan){
                                        //这是用户选择的答案
                                        $answer_log[$qKey]['user_xuan'] = $aVal->answer_xuan;
                                        $answer_log[$qKey]['user_xuan_desc'] = $aVal->answer_xuan.':'.$aVal->answer_title;
                                        break;
                                    }
                                }
                            }
                            //判断各种答题答案是否正确=>为答题结果评论对错、加积分
                            if($dVal==$qVal->true_answer_xuan){
                                if($qVal->type==1){
                                    $dui_dan ++ ;
                                }else if($qVal->type==2){
                                    $dui_duo ++;
                                }else if($qVal->type==3){
                                    $dui_pan ++;
                                }
                                $answer_log[$qKey]['ret'] = 1;
                                $answer_log[$qKey]['score'] = $qVal->score;
                                //分数累计
                                $total_score += $qVal->score;
                            }else{
                                $answer_log[$qKey]['ret'] = 2;
                                $answer_log[$qKey]['score'] = 0;
                            }
                        }else{
                            //表示本题没有作答
                            //记录是哪一题没有作答
                            foreach ($qVal->answers as $aKey=>$aVal){
                                if($qVal->true_answer_xuan == $aVal->answer_xuan){
                                    $answer_log[$qKey]['true_xuan'] = $aVal->answer_xuan;
                                    $answer_log[$qKey]['true_xuan_desc'] = $aVal->answer_xuan.':'.$aVal->answer_title;
                                    $answer_log[$qKey]['ret'] = 0;
                                    $answer_log[$qKey]['score'] = 0;
                                    $dui_dan += 0;
                                    $dui_duo += 0;
                                    $dui_pan += 0;
                                    $total_score += 0;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            //        return $this->reMsg->re(1,'答题成功',$answer_log);
            //        echo '============';var_dump($answer_log);echo '=============';
            Db::beginTransaction();

            $upData = []; //用户存放更新数据
            //更新答题次数
            $answerJoinLog->answer_total_num == 0 ? $upData['answer_total_num'] = 1 : $upData['answer_total_num'] = $answerJoinLog->answer_total_num + 1;
            if($upData['answer_total_num']==1){
                $upData['answer_score_up'] = $total_score;
                $upData['answer_score_down'] = $total_score;
                $upData['answer_used_second_up'] = $answer_used_second;
                $upData['answer_used_second_down'] = $answer_used_second;
                $upData['answer_time_up'] = time();
                $upData['answer_time_down'] = time();
                $upData['answer_danxuan'] = $dui_dan;
                $upData['answer_duoxuan'] = $dui_duo;
                $upData['answer_panduan'] = $dui_pan;
            }else{
                if($total_score>=$answerJoinLog->answer_score_up){
                    $upData['answer_danxuan'] = $dui_dan;
                    $upData['answer_duoxuan'] = $dui_duo;
                    $upData['answer_panduan'] = $dui_pan;
                    $upData['answer_score_up'] = $total_score;
                    $upData['answer_used_second_up'] = $answer_used_second;
                    $upData['answer_time_up'] = time();
                }else if($total_score<$answerJoinLog->answer_score_down){
                    $upData['answer_score_down'] = $total_score;
                    $upData['answer_used_second_down'] = $answer_used_second;
                    $upData['answer_time_down'] = time();
                }
            }
            //字段answer_log
            $the_answer_log = [];
            if($answerJoinLog->answer_log){
                $the_answer_log = json_decode($answerJoinLog->answer_log,true);
            }
            $the_answer_log[$upData['answer_total_num']] = [
                'answer_danxuan' => $dui_dan,
                'answer_duoxuan' => $dui_duo,
                'answer_panduan' => $dui_pan,
                'answer_score' => $total_score,
                'answer_used_second' => $answer_used_second,
                'answer_time' => date('Y-m-d H:i',time())
            ];

            //计算本次答题对的总题数
            $success_num = $dui_dan + $dui_duo + $dui_pan;

            $upData['answer_true'] = $success_num;
            $upData['answer_total_true'] = $answerJoinLog->answer_total_true + $success_num;
            $upData['answer_total_score'] = $answerJoinLog->answer_total_score + $total_score;
//            $upData['answer_log'] = json_encode($the_answer_log); //不在此记录过程
            $upData['answer_score'] = $total_score;
            $upData['answer_used_second'] = $answer_used_second;
            $upData['answer_time'] = time();
            //        var_dump($upData);
            //更新答题数据
            ActAnswerJoin::where('id',$answerJoinLog->id)->update($upData);
            //记录答题过程
            Db::table('act_answer_log')->insert($answer_log);

            //获取本组的所有
//            $groupInfo = TaskLog::where(['version'=>$version,'group_id'=>$group_id])
//                ->selectRaw('id,sum(answer_total_score) as group_score')->first();
            $backData = [
//                'group_score' => intval($groupInfo->group_score),
                'answer_true'=>$success_num,
                'answer_score'=>$total_score,
                'answer_score_up'=>$total_score>=$answerJoinLog->answer_score_up ? $total_score : $answerJoinLog->answer_score_up
            ];
            //判断答题是否正确
            if($backData['answer_true']>0){
                //加积分
                $params = [
                    'type'=> 5, //积分类型 type 1:学习 2:评论 4:支部活动点赞 5:答题 6:报名 7:抽奖 8:签到 9:问卷 10:支部信息更新
                    'action' => 1, //action 1:加积分 2:减积分
                    'uid' => $_user->id,  //用户id
                    'party_id' => $_user->party_id  //支部id
                ];
                $this->makeIntegralLog($params);
            }
            Db::commit();
            return $this->reMsg->re(1,'success',$backData);
        }catch (\Exception $exception){
            Db::rollBack();
            return $this->diyError->errorJson($exception);
        }
    }



    /**
     * 活动答题最新记录
     * @param int $act_id
     * @return object
     */
    #[RequestMapping(path: 'answerLogLatest/{act_id}',methods: 'get')]
    public function answerLogLatest(int $act_id) :object
    {
        try{
            //验证用户信息
            $checkInfo = $this->checkUser();
            if($checkInfo['status']==40002) return $this->reMsg->re(10002,$checkInfo['message']);
            $_user = $checkInfo['data'];

            //先获取本次答题活动
//            $info = Act::where('id',$act_id)->selectRaw('id,type')->first();
//            if(empty($info)) return $this->reMsg->re(10008);
//            if(!in_array($info->type,[1])) return $this->reMsg->re(0,'活动类型有误');
            $logWhere['act_id'] = $act_id;
            $logWhere['uid'] = $_user->id;
            $latestInfo = ActAnswerLog::where($logWhere)->selectRaw('id,count')->orderByDesc('id')->first();
            $list = [];
            if($latestInfo){
                $logWhere['count'] = $latestInfo->count;
                $logList = ActAnswerLog::where($logWhere)->selectRaw('id,act_id,uid,count,question_id,question_title,ret,score,true_xuan,user_xuan,used_second')->get();

                //获取所有的问题id
                $questionIds = [];
                foreach ($logList as $key=>$value) {
                    $questionIds[$key] = $value->question_id;
                }
                $list = ActAnswerQuestion::with(['answers'=>function($query){
                    $query->selectRaw('id,question_id,answer_title,answer_xuan')->get();
                }])->whereIn('id',$questionIds)->get();
                if($list->isNotEmpty()){
                    foreach ($list as $lKey=>$lVal){
                        foreach ($logList as $oKey=>$oVal){
                            if($lVal->id==$oVal->question_id){
                                $lVal->user_xuan = $oVal->user_xuan;
                            }
                        }
                    }
                }
            }
            return $this->reMsg->re(1,'success',['list' => $list]);
        }catch (\Exception $exception){
            return $this->diyError->errorJson($exception);
        }
    }



    /**
     * 活动答题分数排行
     * @param int $act_id
     * @return object
     */
    #[RequestMapping(path: 'answerScoreRank/{act_id}',methods: 'get')]
    public function answerScoreRank(int $act_id) :object
    {
        try{
            //验证用户信息
            $checkInfo = $this->checkUser();
            if($checkInfo['status']==40002) return $this->reMsg->re(10002,$checkInfo['message']);

            //先获取本次答题活动
            $info = Act::where('id',$act_id)->selectRaw('id,type')->first();
            if(empty($info)) return $this->reMsg->re(10008);
            if($info->type != 1) return $this->reMsg->re(0,'活动类型有误');

            $page = $this->request->input('page', 1);
            $limit = $this->request->input('limit', 20);
            $offset = ($page - 1) * $limit;

            $list = ActAnswerJoin::with(['user'=>function($query){
                    $query->selectRaw('id,nickname,avatar,auth_name')->get();
                }])
                ->where('act_id',$act_id)
                ->selectRaw('id,act_id,uid,answer_score_up,answer_total_score,created_at')
                ->orderByDesc('answer_score_up')
                ->orderBy('created_at')
                ->offset($offset)
                ->limit($limit)
                ->get();
            $next = 0;
            if($list->isNotEmpty()){
                if(count($list)>$limit) $next = 1;
            }
            return $this->reMsg->re(1,'success',['list' => $list, 'next' => $next]);
        }catch (\Exception $exception){
            return $this->diyError->errorJson($exception);
        }
    }

}